
package org.upt.dcda.presentation;

import javax.servlet.http.HttpServletRequest;

import org.jboss.resteasy.logging.Logger;
import org.upt.dcda.db.UserEntity;

public class SessionAttributes
{

	private static final Logger	logger	= Logger.getLogger(SessionAttributes.class);

	public static final String	USER	= "user";

	public static boolean isLoggedIn(HttpServletRequest request)
	{
		try
		{
			return request.getSession().getAttribute(USER) != null;
		}
		catch (NullPointerException npe)
		{
			return false;
		}
		catch (Throwable t)
		{
			logger.error("Caught : " + t, t);
			return false;
		}
	}

	public static boolean isAdmin(HttpServletRequest request)
	{
		try
		{
			final UserEntity user = (UserEntity) request.getSession().getAttribute(USER);
			return user.isAdmin();
		}
		catch (NullPointerException npe)
		{
			return false;
		}
		catch (Throwable t)
		{
			logger.error("Caught : " + t, t);
			return false;
		}
	}
}
